package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.HouseBooked;
import com.ruoyi.system.service.IHouseBookedService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 房屋预约Controller
 * 
 * @author ruoyi
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/system/booked")
public class HouseBookedController extends BaseController
{
    @Resource
    private IHouseBookedService houseBookedService;

    /**
     * 查询房屋预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:booked:list')")
    @GetMapping("/list")
    public TableDataInfo list(HouseBooked houseBooked)
    {
        startPage();
        List<HouseBooked> list = houseBookedService.selectHouseBookedList(houseBooked);
        return getDataTable(list);
    }

    /**
     * 导出房屋预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:booked:export')")
    @Log(title = "房屋预约", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseBooked houseBooked)
    {
        List<HouseBooked> list = houseBookedService.selectHouseBookedList(houseBooked);
        ExcelUtil<HouseBooked> util = new ExcelUtil<HouseBooked>(HouseBooked.class);
        return util.exportExcel(list, "booked");
    }

    /**
     * 获取房屋预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:booked:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseBookedService.selectHouseBookedById(id));
    }

    /**
     * 新增房屋预约
     */
    @PreAuthorize("@ss.hasPermi('system:booked:add')")
    @Log(title = "房屋预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseBooked houseBooked)
    {
        return toAjax(houseBookedService.insertHouseBooked(houseBooked));
    }

    /**
     * 修改房屋预约
     */
    @PreAuthorize("@ss.hasPermi('system:booked:edit')")
    @Log(title = "房屋预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseBooked houseBooked)
    {
        return toAjax(houseBookedService.updateHouseBooked(houseBooked));
    }

    /**
     * 删除房屋预约
     */
    @PreAuthorize("@ss.hasPermi('system:booked:remove')")
    @Log(title = "房屋预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseBookedService.deleteHouseBookedByIds(ids));
    }
}
